<?php
namespace app\admin\Controller;
use think\Controller;
use think\Request;
use think\facade\Env;
use think\Db;
use think\facade\Session;

class Findpassword extends Controller
{
	public function index(){
		return $this -> view -> fetch('index');
	}
    public function updatepassword(Request $request){
		if(Request()->isAjax()){
		$data = $request->param();
		if($data){
			if(isset($data['publishkey']) || !empty($data['publishkey'])){
				$password = Db::name('system')->field('publishkey')->find(1);
				if(password_verify($data['publishkey'],$password['publishkey'])){
					$admin = Db::name('admin')->where('name',$data['name'])->find();
					if($admin){
						$res = Db::name('admin')->where('name',$data['name'])->update(['password'=>password_hash($data['password'],PASSWORD_DEFAULT)]);
						if($res){
							return jsonmsg(1,'账号{$data["name"]}密码重置成功');
						}else{
							return jsonmsg(0,'账号{$data["name"]}密码重置失败');
						}
					}else{
						return jsonmsg(0,'账号{$data["name"]}不存在');
					}
				}else{
					return jsonmsg(0,'密令错误');
				}
			}else{
				return jsonmsg(0,'未设置安全密令');
			}
		}else{
			return jsonmsg(0,'参数错误');
		}
		}else{
			return jsonmsg(0,"请求类型错误");
		}
	}
}